let token = sessionStorage.getItem("token");
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值

}
let id = "";
$(function () {
    id = getUrlParam('id');
    $.ajax({
        url: testurl + "motion/degree_info",
        type: "post",
        headers: { "Authorization": "Bearer " + token },
        contentType: "application/json",
        data: JSON.stringify({
            "motion_id": id
        }),
        success: function (data) {

            $("#no").html(data.obj.no);
            $("#realname").html(data.obj.realname);
            $("#organ_post").html(data.obj.organ_post);
            $("#title").html(data.obj.title);
            $("#bldw").html(data.obj.bldw);
            $("#tel_num").val(data.obj.tel_num);
            $("#letter_num").val(data.obj.letter_num);
            $("#face_num").val(data.obj.face_num);
            $("#no_contact").val(data.obj.no_contact);
            if (data.obj.handle_attitude === "1"){
                $("input[name='RadioButtonList1']").eq(0).attr("checked",true);
            } else if (data.obj.handle_attitude === "2") {
                $("input[name='RadioButtonList1']").eq(1).attr("checked", true);
            } else if (data.obj.handle_attitude === "3") {
                $("input[name='RadioButtonList1']").eq(2).attr("checked", true);
            } else if (data.obj.handle_attitude === "4") {
                $("input[name='RadioButtonList1']").eq(3).attr("checked", true);
            }
            if (data.obj.handle_result === "1") {
                $("input[name='RadioButtonList2']").eq(0).attr("checked", true);
            } else if (data.obj.handle_result === "2") {
                $("input[name='RadioButtonList2']").eq(1).attr("checked", true);
            } else if (data.obj.handle_result === "3") {
                $("input[name='RadioButtonList2']").eq(2).attr("checked", true);
            } else if (data.obj.handle_result === "4") {
                $("input[name='RadioButtonList2']").eq(3).attr("checked", true);
            }
            $("#suggest").val(data.obj.suggest);
        }
    })
});
function submitEv() {
    let tel_num = $("#tel_num").val();
    let letter_num = $("#letter_num").val();
    let face_num = $("#face_num").val();
    let no_contact = $("#no_contact").val();
    let suggest = $("#suggest").val();
    let handle_attitude = $("input[name='RadioButtonList1']:checked").val();
    let handle_result = $("input[name='RadioButtonList2']:checked").val();
    $.ajax({
        url: testurl + "motion/degree",
        type: "post",
        headers: { "Authorization": "Bearer " + token },
        contentType: "application/json",
        data: JSON.stringify({
            "id": id,//议案id
            "tel_num": tel_num,//电话沟通
            "letter_num": letter_num,//信函沟通
            "face_num": face_num,//面对面沟通
            "no_contact": no_contact,//未联系
            "handle_attitude": handle_attitude,//办理态度 1很满意 2满意 3基本满意 4不满意
            "handle_result": handle_result,//办理结果 1很满意 2满意 3基本满意 4不满意
            "suggest": suggest
        }),
        success: function (data) {
            if (data.success === true) {
                alert("成功");
                window.close()
            } else {
                alert("失败");
                window.close()
            }
        }
    })
}